package com.easy.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.easy.entity.enums.PageSize;
import com.easy.entity.query.DeptQuery;
import com.easy.entity.po.Dept;
import com.easy.entity.vo.PaginationResultVO;
import com.easy.entity.query.SimplePage;
import com.easy.mappers.DeptMapper;
import com.easy.service.DeptService;
import com.easy.utils.StringTools;


/**
 * 部门表 业务接口实现
 */
@Service("deptService")
public class DeptServiceImpl implements DeptService {

	@Resource
	private DeptMapper<Dept, DeptQuery> deptMapper;

	/**
	 * 根据条件查询列表
	 */
	@Override
	public List<Dept> findListByParam(DeptQuery param) {
		return this.deptMapper.selectList(param);
	}

	/**
	 * 根据条件查询列表
	 */
	@Override
	public Integer findCountByParam(DeptQuery param) {
		return this.deptMapper.selectCount(param);
	}

	/**
	 * 分页查询方法
	 */
	@Override
	public PaginationResultVO<Dept> findListByPage(DeptQuery param) {
		int count = this.findCountByParam(param);
		int pageSize = param.getPageSize() == null ? PageSize.SIZE15.getSize() : param.getPageSize();

		SimplePage page = new SimplePage(param.getPageNo(), count, pageSize);
		param.setSimplePage(page);
		List<Dept> list = this.findListByParam(param);
		PaginationResultVO<Dept> result = new PaginationResultVO(count, page.getPageSize(), page.getPageNo(), page.getPageTotal(), list);
		return result;
	}

	/**
	 * 新增
	 */
	@Override
	public Integer add(Dept bean) {
		return this.deptMapper.insert(bean);
	}

	/**
	 * 批量新增
	 */
	@Override
	public Integer addBatch(List<Dept> listBean) {
		if (listBean == null || listBean.isEmpty()) {
			return 0;
		}
		return this.deptMapper.insertBatch(listBean);
	}

	/**
	 * 批量新增或者修改
	 */
	@Override
	public Integer addOrUpdateBatch(List<Dept> listBean) {
		if (listBean == null || listBean.isEmpty()) {
			return 0;
		}
		return this.deptMapper.insertOrUpdateBatch(listBean);
	}

	/**
	 * 多条件更新
	 */
	@Override
	public Integer updateByParam(Dept bean, DeptQuery param) {
		StringTools.checkParam(param);
		return this.deptMapper.updateByParam(bean, param);
	}

	/**
	 * 多条件删除
	 */
	@Override
	public Integer deleteByParam(DeptQuery param) {
		StringTools.checkParam(param);
		return this.deptMapper.deleteByParam(param);
	}

	/**
	 * 根据Id获取对象
	 */
	@Override
	public Dept getDeptById(Integer id) {
		return this.deptMapper.selectById(id);
	}

	/**
	 * 根据Id修改
	 */
	@Override
	public Integer updateDeptById(Dept bean, Integer id) {
		return this.deptMapper.updateById(bean, id);
	}

	/**
	 * 根据Id删除
	 */
	@Override
	public Integer deleteDeptById(Integer id) {
		return this.deptMapper.deleteById(id);
	}

	/**
	 * 根据Name获取对象
	 */
	@Override
	public Dept getDeptByName(String name) {
		return this.deptMapper.selectByName(name);
	}

	/**
	 * 根据Name修改
	 */
	@Override
	public Integer updateDeptByName(Dept bean, String name) {
		return this.deptMapper.updateByName(bean, name);
	}

	/**
	 * 根据Name删除
	 */
	@Override
	public Integer deleteDeptByName(String name) {
		return this.deptMapper.deleteByName(name);
	}
}